/*
 * LocationOps.java
 *
 * Created on July 25, 2007, 8:11 PM
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.admin;

import javax.swing.JOptionPane;
import org.fpdev.apps.admin.gui.dialogs.LandmarkNewLocationDialog;

/**
 *
 * @author demory
 */
public class LocationOps {

  private AdminClient av_;

  /** Creates a new instance of LocationOps */
  public LocationOps(AdminClient av) {
    av_ = av;
  }

  public void newLandmark() {
    String name = JOptionPane.showInputDialog(av_.getGUI(), "Enter primary name:");
    if (name == null || name.length() == 0) {
      return;
    }
    String altNames = JOptionPane.showInputDialog(av_.getGUI(), "Enter alternate name(s):");
    if (altNames == null) {
      return;
    }
    new LandmarkNewLocationDialog(av_, name, altNames);
  }

  public void initLandmark(String name, String loc, String altnames) {
    av_.getEngine().getDB().setActiveTable("landmarks");
    av_.getEngine().getDB().initLandmark(name, loc, altnames);
    av_.getEngine().getDB().flushInsertOps();
    av_.getGUI().getLandmarksFrame().loadFromDB();
    av_.getGUI().getLandmarksFrame().updateTable(false);
    av_.getGUI().getLandmarksFrame().toFront();
  }

  public void updateLandmark(String name, String loc, String altnames) {
    av_.getEngine().getDB().updateLandmark(name, loc, altnames);
    av_.getGUI().getLandmarksFrame().loadFromDB();
    av_.getGUI().getLandmarksFrame().updateTable(false);
    av_.getGUI().getLandmarksFrame().toFront();
  }
}
